package com.lap.framework.junit.domain.generator;

import com.lap.framework.junit.shared.tool.CodeType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CodeGeneratorFactory {

  public static final Map<CodeType, CodeGenerator> MAP = new HashMap<>();

  static {
    register(new JavaCodeGenerator());
    register(new CvsGenerator());
  }

  public static void register(CodeGenerator generator) {
    MAP.put(generator.getType(), generator);
  }

  public static CodeGenerator getGenerator(CodeType type) {
    CodeGenerator generator = MAP.get(type);
    if (generator == null) {
      throw new IllegalArgumentException("不支持的生成器类型: " + type + ", 可用类型: " + getSupportedTypes());
    }
    return generator;
  }

  private static List<CodeType> getSupportedTypes() {
    return new ArrayList<>(MAP.keySet());
  }
}
